﻿Imports System.Data
Imports ADOEntity

Partial Class Administrator_UserRightList
    Inherits Web.UI.BasePage

    ' Dim userRightEntity As New userEntities
    Dim dsUserRight As New DataSet
    Dim clsQuery As clsDatabase
    Dim intBeforeItemIndex As Integer
    Dim clsDataTable As New clsLINQToDataTable
    Dim sUserRightEntity As userEntities
    Dim strMsg As String = ""
    Dim clsSessionMenuRight As clsSessionMenuRight
    Dim clsMasterDropDown As clsMasterDropDown
#Region " Even Page "

    Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init

        'lblUserRightDesc.Text = Resources.resUserRight.userRightDesc
        ' lblDept.Text = Resources.resBranch.department
        btnSearch.Text = Resources.resButton.btnSearch
        btnAdd.Text = Resources.resButton.btnAdd
        btnModify.Text = Resources.resButton.btnModify
        btnDelete.Text = Resources.resButton.btnDelete
        btnClear.Text = Resources.resButton.btnClear
        btnPrint.Text = "พิมพ์กลุ่มสิทธิ์"
        btnPrintDetail.Text = "พิมพ์รายละเอียดกลุ่มสิทธิ์"
        lblMsg.Text = Resources.resMessageAlert.alertEmptyGrid

    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            chkIsLogin()
            clsMasterDropDown = New clsMasterDropDown
            clsSessionMenuRight = Session("ClsMenuRight")

            If (Not IsPostBack) Then

                CreateControlMP()
                setData()
                lblMsg.Visible = False
            Else
                dsUserRight = Session("dsTblMaster")
                gvUserRight.DataSource = dsUserRight.Tables("sUserRight")
                gvUserRight.DataBind()
            End If
        Catch ex As Exception

        End Try


    End Sub

    Protected Sub Page_Unload(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Unload
        Session("dsTblMaster") = dsUserRight
    End Sub


#End Region

#Region "SetForm"

    Sub CreateControlMP()

        Dim lblForm As Label = CType(Master.FindControl("lblForm"), Label)
        lblForm.Text = "กลุ่มสิทธิ์"
    End Sub

#End Region

#Region " Even Button "

    Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearch.Click
        sUserRightEntity = New UserEntities
        clsSessionMenuRight = Session("ClsMenuRight")
        'setButton(1)
        IsDataBind()
        clearGvIndex()
        SaveLogSearch()
    End Sub

    Protected Sub btnAdd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        Response.Redirect("userRightEdit.aspx?Status=Add")

        'clsSessionMenuRight = Session("ClsMenuRight")
        'If chkBeforeSave() Then
        '    sUserRightEntity = New UserEntities
        '    Dim sUserRight As New SUSERRIGHT
        '    Dim userDept As New USERRIGHTDEPT
        '    sUserRightEntity.Connection.Open()
        '    Using transaction As System.Data.Common.DbTransaction = sUserRightEntity.Connection.BeginTransaction()
        '        Try
        '            sUserRight.USERRIGHT = txtUserRight.Text
        '            sUserRight.USERRIGHTDESC = txtUserRightDesc.Text
        '            sUserRight.ROLEGHB = If(chkRoleGHB.Checked = True, 1, 0)
        '            sUserRight.ROLESYS = If(ChkRoleSys.Checked = True, 1, 0)
        '            sUserRight.ROLEDEPT = If(chkRoleDept.Checked = True, 1, 0)
        '            sUserRight.ROLEZONE = If(chkRoleZone.Checked = True, 1, 0)
        '            sUserRight.ROLEBRANCH = If(chkRoleBranch.Checked = True, 1, 0)
        '            sUserRight.ROLEUSER = If(chkRoleUser.Checked = True, 1, 0)
        '            sUserRightEntity.AddToSUSERRIGHT(sUserRight)

        '            userDept.USERRIGHT = txtUserRight.Text
        '            userDept.DEPTCODE = ddlDepartment.SelectedValue
        '            sUserRightEntity.AddToUSERRIGHTDEPT(userDept)

        '            sUserRightEntity.SaveChanges()
        '            transaction.Commit()
        '        Catch ex As System.Data.UpdateException
        '            Dim codeError() As String = ex.InnerException.Message.Split(":")
        '            If codeError(0) = "ORA-00001" Then
        '                ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('ไม่สามารถเพิ่มได้ เนื่องจากรหัสนี้มีการนำมาใช้ในระบบแล้ว')", True)
        '            Else
        '                ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('" + ex.InnerException.Message + "')", True)
        '            End If
        '            transaction.Rollback()
        '        Catch ex As Exception
        '            ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('บันทึกผิดพลาด')", True)
        '            transaction.Rollback()
        '        End Try
        '    End Using

        '    IsDataBind()
        '    reset()

        '    ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('" + Resources.resMsgKYC.msgSave + "')", True)
        'Else
        '    ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('" + strMsg + "')", True)
        'End If
    End Sub

    Protected Sub btnModify_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnModify.Click
        If Not (gvUserRight.SelectedIndex = -1) Then
            Response.Redirect("userRightEdit.aspx?Status=Edit&strUserRight=" + gvUserRight.Rows(gvUserRight.SelectedIndex).Cells(1).Text)
        Else
            ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('" + Resources.resValidate.nonSelectGrid + "')", True)

        End If

        'clsSessionMenuRight = Session("ClsMenuRight")
        'sUserRightEntity = New UserEntities
        'Dim sUserRight As New SUSERRIGHT
        'Dim userRightDept As New USERRIGHTDEPT

        'If chkBeforeSave() Then


        '    sUserRightEntity.Connection.Open()
        '    Using transaction As System.Data.Common.DbTransaction = sUserRightEntity.Connection.BeginTransaction()
        '        Try
        '            Dim qry = (From UserRight In sUserRightEntity.SUSERRIGHT Where UserRight.USERRIGHT = txtUserRight.Text).ToList

        '            qry(0).USERRIGHTDESC = txtUserRightDesc.Text
        '            qry(0).ROLEGHB = If(chkRoleGHB.Checked = True, 1, 0)
        '            qry(0).ROLESYS = If(ChkRoleSys.Checked = True, 1, 0)
        '            qry(0).ROLEDEPT = If(chkRoleDept.Checked = True, 1, 0)
        '            qry(0).ROLEZONE = If(chkRoleZone.Checked = True, 1, 0)
        '            qry(0).ROLEBRANCH = If(chkRoleBranch.Checked = True, 1, 0)
        '            qry(0).ROLEUSER = If(chkRoleUser.Checked = True, 1, 0)

        '            Dim txtDeptCode As String = CType(gvUserRight.Rows(gvUserRight.SelectedIndex).FindControl("hdfDeptCode"), HiddenField).Value

        '            Dim qryUserDept = (From userDept In sUserRightEntity.USERRIGHTDEPT Where userDept.USERRIGHT = txtUserRight.Text And userDept.DEPTCODE = txtDeptCode).ToList
        '            sUserRightEntity.DeleteObject(qryUserDept(0))

        '            userRightDept.USERRIGHT = txtUserRight.Text
        '            userRightDept.DEPTCODE = ddlDepartment.SelectedValue
        '            sUserRightEntity.AddToUSERRIGHTDEPT(userRightDept)

        '            sUserRightEntity.SaveChanges()
        '            transaction.Commit()


        '            ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('" + Resources.resMsgKYC.msgSave + "')", True)
        '        Catch ex As System.Data.UpdateException
        '            ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('" + ex.InnerException.Message + "')", True)
        '            transaction.Rollback()
        '        Catch ex As Exception
        '            ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('บันทึกผิดพลาด')", True)
        '            transaction.Rollback()
        '        End Try
        '    End Using

        '    IsDataBind()
        '    reset()
        'Else
        '    ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('" + strMsg + "')", True)
        'End If

       
    End Sub

    Protected Sub btnDelete_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDelete.Click

        clsSessionMenuRight = Session("ClsMenuRight")
        sUserRightEntity = New UserEntities

        If Not (gvUserRight.SelectedIndex = -1) Then
            Dim UserRight As String = gvUserRight.Rows(gvUserRight.SelectedIndex).Cells(1).Text
            sUserRightEntity.Connection.Open()
            Using transaction As System.Data.Common.DbTransaction = sUserRightEntity.Connection.BeginTransaction()
                Try
                    '  Dim txtDeptCode As String = CType(gvUserRight.Rows(gvUserRight.SelectedIndex).FindControl("hdfDeptCode"), HiddenField).Value
                    Dim qryUserDept = (From userDept In sUserRightEntity.USERRIGHTDEPT Where userDept.USERRIGHT = UserRight).ToList

                    Dim icountTbl As Integer = qryUserDept.Count
                    For i As Integer = 0 To icountTbl - 1
                        sUserRightEntity.DeleteObject(qryUserDept(i))
                        sUserRightEntity.SaveChanges()
                    Next


                    Dim qry = (From s_UserRight In sUserRightEntity.SUSERRIGHT Where s_UserRight.USERRIGHT = UserRight).ToList
                    sUserRightEntity.DeleteObject(qry(0))
                    sUserRightEntity.SaveChanges()
                    transaction.Commit()

                    SaveLogDelete(UserRight)

                Catch ex As System.Data.UpdateException
                    Dim codeError() As String = ex.InnerException.Message.Split(":")
                    If codeError(0) = "ORA-02292" Then
                        ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('ไม่สามารถลบได้ เนื่องจากมีการนำมาใช้ในระบบแล้ว')", True)
                    Else
                        WriteError(ex, "btnDelete_Click", "UserRightList")
                        ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('" + ex.InnerException.Message + "')", True)
                    End If
                    transaction.Rollback()
                Catch ex As Exception
                    WriteError(ex, "btnDelete_Click", "UserRightList")
                    ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('" + Resources.resError.errorMessage + "')", True)
                    transaction.Rollback()
                End Try

            End Using
            IsDataBind()
            reset()
        Else
            ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('" + Resources.resValidate.nonSelectGrid + "')", True)

        End If
     

    End Sub

    Protected Sub btnClear_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnClear.Click
        clear()
    End Sub

    Protected Sub btnPrint_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPrint.Click
        'Dim param As String = "{ 'RPTTYPE' : '" & ddlRrptType.SelectedValue & "'," _
        '                             & "'RPTYEAR' : '" & txtYear.Text.Trim & "'," _
        '                             & "'DEPTCODE' : '" & ddlDepartment.SelectedValue & "'," _
        '                             & "'BRANCHCODE' : '" & ddlBranch.SelectedValue & "'," _
        '                             & "'RPTNO' : '" & txtNo.Text.Trim & "'," _
        '                             & "'TYPEDATE' : '" & rdolTypeDate.SelectedValue & "'," _
        '                             & "'STARTDATE' : '" & strConvertDateStart & "'," _
        '                             & "'ENDDATE' : '" & strConvertDateEnd & "'," _
        '                             & "'SIGNTYPE' : '" & If(rdolSignType.SelectedValue = 0, "", rdolSignType.SelectedValue) & "'," _
        '                             & "'ISSEND' : '" & If(rdolIsSend.SelectedValue = 0, "", rdolIsSend.SelectedValue) & "'}"
        'ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType, "key", _
        '        "OpenWindowWithPost('../Form/frmRptAmlo.aspx','width=730,height=345,left=100,top=100,resizable=yes,scrollbars=yes','Report', " + param + ");", True)

        Dim param As String = "{ 'rptType' : '2'," _
                             & "'UserRight' : '" & txtUserRight.Text.Trim & "'," _
                              & "'UserRightDesc' : '" & txtUserRightDesc.Text.Trim & "'," _
                              & "'UserRightStatus' : '" & rdolStatus.SelectedValue & "/" & rdolStatus.SelectedItem.Text & "'}"
        ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType, "key", "OpenWindowWithPost('../Form/frmPrintRptMaster.aspx','width=730,height=345,left=100,top=100,resizable=yes,scrollbars=yes','Report', " + param + ");", True)

        SaveLogPrint()
        'Dim param As String = "{ 'rptType' : '2'}"
        'ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType, "key", "OpenWindowWithPost('../Form/frmRptMaster.aspx','width=730,height=345,left=100,top=100,resizable=yes,scrollbars=yes','Report', " + param + ");", True)
    End Sub

#End Region

#Region "Even GridView"
    Protected Sub gvUserRight_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles gvUserRight.SelectedIndexChanged

        If (gvUserRight.SelectedIndex = intBeforeItemIndex) Then
            clearGvIndex()
            reset()

            'btnModify.Text = "แก้ไข"
        Else
            'btnModify.Text = "บันทึก"

            'Dim chkTemp As New CheckBox
            'setButton(2)


            'txtUserRight.Text = gvUserRight.Rows(gvUserRight.SelectedIndex).Cells(1).Text
            'txtUserRightDesc.Text = gvUserRight.Rows(gvUserRight.SelectedIndex).Cells(2).Text

            'chkTemp = CType(gvUserRight.Rows(gvUserRight.SelectedIndex).Cells(3).FindControl("chkAdGhb"), CheckBox)
            'chkRoleGHB.Checked = chkTemp.Checked
            'chkTemp = CType(gvUserRight.Rows(gvUserRight.SelectedIndex).Cells(4).FindControl("chkAdSys"), CheckBox)
            'ChkRoleSys.Checked = chkTemp.Checked
            'chkTemp = CType(gvUserRight.Rows(gvUserRight.SelectedIndex).Cells(5).FindControl("chkAdDept"), CheckBox)
            'chkRoleDept.Checked = chkTemp.Checked
            'chkTemp = CType(gvUserRight.Rows(gvUserRight.SelectedIndex).Cells(6).FindControl("chkAdZone"), CheckBox)
            'chkRoleZone.Checked = chkTemp.Checked
            'chkTemp = CType(gvUserRight.Rows(gvUserRight.SelectedIndex).Cells(7).FindControl("chkAdBranch"), CheckBox)
            'chkRoleBranch.Checked = chkTemp.Checked
            'chkTemp = CType(gvUserRight.Rows(gvUserRight.SelectedIndex).Cells(8).FindControl("chkUser"), CheckBox)
            'chkRoleUser.Checked = chkTemp.Checked

            'Dim txtDeptCode As String = CType(gvUserRight.Rows(gvUserRight.SelectedIndex).FindControl("hdfDeptCode"), HiddenField).Value
            'If Not (txtDeptCode = "") Then
            '    ddlDepartment.SelectedValue = txtDeptCode
            'End If


            btnDelete.Attributes.Add("onclick", "return confirm('" + String.Format(Resources.resValidate.confirmDelete, _
                                                                          IIf(gvUserRight.SelectedIndex = -1, "", gvUserRight.Rows(gvUserRight.SelectedIndex).Cells(2).Text)) + "');")
        End If

     
    End Sub

    Protected Sub gvUserRight_SelectedIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSelectEventArgs) Handles gvUserRight.SelectedIndexChanging
        intBeforeItemIndex = gvUserRight.SelectedIndex
    End Sub

    Protected Sub gvUserRight_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles gvUserRight.PageIndexChanging
        gvUserRight.PageIndex = e.NewPageIndex
        clearGvIndex()
        DataBind()
    End Sub

    Protected Sub gvUserRight_Sorting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSortEventArgs) Handles gvUserRight.Sorting
        Dim dt = TryCast(dsUserRight.Tables("sUserRight"), DataTable)

        If dt IsNot Nothing Then

            'Sort the data.
            dt.DefaultView.Sort = e.SortExpression & " " & GetSortDirection(e.SortExpression)
            gvUserRight.DataSource = dsUserRight.Tables("sUserRight")
            gvUserRight.DataBind()
            clearGvIndex()
        End If
    End Sub
#End Region

#Region " Function"
    Private Sub setData()
        rdolStatus.SelectedValue = -1

        'clsMasterDropDown.setDeptToDdlSearch(ddlDepartment, _
        '                                strDeptCode:=clsSessionMenuRight.getDeptCode, _
        '                                strRoleCode:=clsSessionMenuRight.getRoleGroup)



    End Sub

    Private Sub clearGvIndex()
        gvUserRight.SelectedIndex = -1
        btnDelete.Attributes.Clear()
    End Sub

    Private Sub IsDataBind()
        Try
            If dsUserRight.Tables.Contains("sUserRight") Then
                dsUserRight.Tables.Clear()
            End If


            Dim qryUserRight = From ur In sUserRightEntity.SUSERRIGHT Group Join _
                                    urdept In sUserRightEntity.USERRIGHTDEPT _
                                    On ur.USERRIGHT Equals urdept.USERRIGHT Into leftUserRight = Group
                               From tblUserRight In leftUserRight.DefaultIfEmpty Group Join _
                                    department In sUserRightEntity.SDEPARTMENT _
                                    On tblUserRight.DEPTCODE Equals department.DEPTCODE Into leftTblUserRight = Group
                                    From tblLeftAll In leftTblUserRight.DefaultIfEmpty
                               Order By ur.USERRIGHT Ascending, tblUserRight.USERRIGHT Ascending
                                Select ur.USERRIGHT, ur.USERRIGHTDESC, ur.ROLEGHB, ur.ROLESYS, _
                                        ur.ROLEDEPT, ur.ROLEZONE, ur.ROLEBRANCH, ur.ROLEUSER, ur.STATUS, tblUserRight.DEPTCODE
            ', tblLeftAll.DEPTCODE, tblLeftAll.DEPTNAME


            If (clsSessionMenuRight.getRoleGroup > 89) Then
                'qryUserRight = qryUserRight.Where(Function(fn) fn.ROLEGHB = 1)
            ElseIf (clsSessionMenuRight.getRoleGroup > 79) Then
                'qryUserRight = qryUserRight.Where(Function(fn) fn.ROLESYS = 1)
            ElseIf (clsSessionMenuRight.getRoleGroup > 69) Then
                qryUserRight = qryUserRight.Where(Function(fn) (fn.ROLEDEPT = 1 Or fn.ROLEZONE = 1 Or fn.ROLEBRANCH = 1 Or fn.ROLEUSER = 1) And fn.DEPTCODE = clsSessionMenuRight.getDeptCode)

            ElseIf (clsSessionMenuRight.getRoleGroup > 59) Then
                qryUserRight = qryUserRight.Where(Function(fn) (fn.ROLEZONE = 1 Or fn.ROLEBRANCH = 1 Or fn.ROLEUSER = 1) And fn.DEPTCODE = clsSessionMenuRight.getDeptCode)
            ElseIf (clsSessionMenuRight.getRoleGroup > 49) Then
                qryUserRight = qryUserRight.Where(Function(fn) (fn.ROLEBRANCH = 1 Or fn.ROLEUSER = 1) And fn.DEPTCODE = clsSessionMenuRight.getDeptCode)
            ElseIf (clsSessionMenuRight.getRoleGroup < 50) Then
                qryUserRight = qryUserRight.Where(Function(fn) fn.ROLEUSER = 1)
            End If

            '  qryUserRight = qryUserRight.Where(Function(fn) fn.USERRIGHT <> clsSessionMenuRight.getUserRight)

            If Not (txtUserRight.Text = "") Then
                qryUserRight = qryUserRight.Where(Function(fn) fn.USERRIGHT.Contains(txtUserRight.Text))
            End If

            If Not (txtUserRightDesc.Text = "") Then
                qryUserRight = qryUserRight.Where(Function(fn) fn.USERRIGHTDESC.Contains(txtUserRightDesc.Text))
            End If

            If Not (rdolStatus.SelectedValue = -1) Then
                qryUserRight = qryUserRight.Where(Function(fn) fn.STATUS = rdolStatus.SelectedValue)
            End If

            Dim qryUserRightNew = qryUserRight.Select(Function(fn) New With {fn.USERRIGHT, fn.USERRIGHTDESC, fn.ROLEGHB, fn.ROLESYS, fn.ROLEDEPT, fn.ROLEZONE, fn.ROLEBRANCH, fn.ROLEUSER, fn.STATUS})


            dsUserRight.Tables.Add(clsDataTable.LINQToDataTable(qryUserRightNew.Distinct.OrderBy(Function(fn) fn.USERRIGHT), "sUserRight").Copy)

            If (qryUserRight.Count = 0) Then
                lblMsg.Visible = True
                lblTotal.Text = ""
            Else
                lblMsg.Visible = False
                lblTotal.Text = "จำนวนรายการทั้งหมด " + dsUserRight.Tables("sUserRight").Rows.Count.ToString + " รายการ "
            End If

            gvUserRight.DataSource = dsUserRight.Tables("sUserRight")
            gvUserRight.DataBind()

            clsQuery = Nothing
        Catch ex As Exception
            WriteError(ex, "IsDataBind", "UserRightList")
        End Try

    End Sub

    Private Function GetSortDirection(ByVal column As String) As String

        ' By default, set the sort direction to ascending.
        Dim sortDirection = "DESC"

        ' Retrieve the last column that was sorted.
        Dim sortExpression = TryCast(ViewState("SortExpression"), String)

        If sortExpression IsNot Nothing Then
            ' Check if the same column is being sorted.
            ' Otherwise, the default value can be returned.
            If sortExpression = column Then
                Dim lastDirection = TryCast(ViewState("SortDirection"), String)
                If lastDirection IsNot Nothing _
                  AndAlso lastDirection = "DESC" Then

                    sortDirection = "ASC"

                End If
            End If
        End If

        ' Save new values in ViewState.
        ViewState("SortDirection") = sortDirection
        ViewState("SortExpression") = column
        Return sortDirection
    End Function

    Private Sub setButton(ByVal button As Integer)

        If button = 1 Then 'unselect
            lblMsg.Visible = False

            btnModify.Enabled = False
            btnDelete.Enabled = False

            btnSearch.Enabled = True
            btnAdd.Enabled = True

            txtUserRight.Enabled = True

        ElseIf button = 2 Then 'select

            btnSearch.Enabled = False
            btnAdd.Enabled = False

            btnModify.Enabled = True
            btnDelete.Enabled = True

            txtUserRight.Enabled = False

        End If

    End Sub

    Private Sub clear()
       lblMsg.Visible = False
        txtUserRight.Text = ""
        txtUserRightDesc.Text = ""
        lblTotal.Text = ""
    End Sub

    Private Sub reset()
         clearGvIndex()
        lblMsg.Visible = False
        txtUserRight.Text = ""
        txtUserRightDesc.Text = ""
    
    End Sub

    Private Sub SaveLogSearch()
        Try
          

            Dim desc As String = ""

             If Not (txtUserRight.Text = "") Then
                desc += " รหัสกลุ่มสิทธิ์ - " + txtUserRight.Text
            End If

            If Not (txtUserRightDesc.Text = "") Then
                desc += " ชื่อกลุ่มสิทธิ์ - " + txtUserRightDesc.Text
            End If

            desc += " สถานะ - " + rdolStatus.SelectedItem.Text


            If Not desc = "" Then
                desc = "ค้นหาข้อมูลกลุ่มสิทธิ์ จาก " + desc
            Else
                desc = "ค้นหาทั้งหมด"
            End If

            Dim clsLogTransaction As New clsLogTransaction
            clsLogTransaction.saveLogTransaction("", clsSessionMenuRight.getUserName, 1, desc, "M62")
            clsLogTransaction = Nothing
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Private Sub SaveLogPrint()
        Try

            Dim desc As String = "พิมพ์ข้อมูลกลุ่มสิทธิ์"

            Dim clsLogTransaction As New clsLogTransaction
            clsLogTransaction.saveLogTransaction("", clsSessionMenuRight.getUserName, 2, desc, "M62")
            clsLogTransaction = Nothing
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Private Sub SaveLogDelete(ByVal value As String)
        Try

            Dim desc As String = "ลบข้อมูลกลุ่มสิทธิ์ (รหัสกลุ่มสิทธิ์ " + value + ")"

            Dim clsLogTransaction As New clsLogTransaction
            clsLogTransaction.saveLogTransaction(value, clsSessionMenuRight.getUserName, 5, desc, "M62")
            clsLogTransaction = Nothing
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

#End Region



   
    
   
   
   
    Protected Sub btnPrintDetail_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPrintDetail.Click
        Dim param As String = "{ 'rptType' : '3'," _
                           & "'UserRight' : '" & txtUserRight.Text.Trim & "'," _
                            & "'UserRightDesc' : '" & txtUserRightDesc.Text.Trim & "'," _
                            & "'UserRightStatus' : '" & rdolStatus.SelectedValue & "/" & rdolStatus.SelectedItem.Text & "'}"
        ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType, "key", "OpenWindowWithPost('../Form/frmPrintRptMaster.aspx','width=730,height=345,left=100,top=100,resizable=yes,scrollbars=yes','Report', " + param + ");", True)

        SaveLogPrint()
    End Sub
End Class
